import os

import openpyxl


class ExclUtil:
    @staticmethod
    def getcase(excl_path, sheet_name):
        try:
            # 打开工作簿
            work_book = openpyxl.load_workbook(excl_path)

            # 获取工作表
            if sheet_name in work_book.sheetnames:
                sheet = work_book[sheet_name]
            else:
                sheet = work_book.active  # 如果指定工作表不存在，使用默认工作表

            # 读取数据（示例：读取所有行）
            data = []
            for row in sheet.iter_rows(values_only=True):
                data.append(row)

            return data

        except Exception as e:
            print(f"读取 Excel 文件失败: {e}")
            return []


#
if __name__ == "__main__":
    data = ExclUtil.getcase(os.path.abspath(r"..\data\case.xlsx"), "testcases")
    print("测试数据是", data)
